$(function() {
    var imgh=$('.commodity-img img,.list-img img').width();
    $('body').append("<style>.commodity-img img,.list-img img{height:" +imgh+"px;}</style>");

	/*首页搜索框*/
    $('.home-search form input ').blur(function() { //失去焦点 隐藏搜索框
        //$(".header-home").css('background-color','transparent')
        //$(".home-search form").fadeOut();
        //$('.icon-sousuoclick').fadeIn();
    })
    $('.icon-sousuoclick').click(function(){
        $(".header-home").css('background-color','rgba(0,0,0,0.7)')
        $('.icon-sousuoclick').fadeOut();
        $(".home-search form").fadeIn();
    })
	$(window).scroll(function () {
		if ($(this).scrollTop() > 30) {
            $(".header-home").css('background-color','rgba(0,0,0,0.7)')
            $('.icon-sousuoclick').fadeOut();
            $(".home-search form").fadeIn();
		} else {
            $(".header-home").css('background-color','rgba(0,0,0,0.3)')
            //$(".home-search form").fadeOut();
            //$('.icon-sousuoclick').fadeIn();
		}
    });
	//分类切换
	$('.categoryson-title li').click(function() {
		$(this).addClass('active').siblings().removeClass('active');
		$(this).addClass('active').parent().siblings().find('li').removeClass('active');
		var index = $(this).index();
		//$('.categoryson-title li').removeClass('active').eq(index).addClass('active');
		$('.commodity-wraw').hide().eq(index).fadeIn(50);
	});
    $('.customized>div').click(function() {
        //var index = $(this).index();
        //$('.customized>div').css({"background-color":"#1FB242","color":"#fff","z-index":"1"}).eq(index).css({"background-color":"#fff","color":"#1FB242","z-index":"2"});
        //$('.customized>div').find('span').css("border-bottom","4rem solid #1FB242").eq(index).css("border-bottom","4rem solid #fff");
        //$('.customized-con').hide().eq(index).fadeIn();

        var index = $(this).index();
        $('.customized>div').css({"background-color":"#fff","color":"#1FB242","z-index":"1"}).eq(index).css({"background-color":"#1FB242","color":"#fff","z-index":"2"});
        $('.customized>div').find('span').css("border-bottom","4rem solid #fff").eq(index).css("border-bottom","4rem solid #1FB242");
        $('.customized-con').hide().eq(index).fadeIn();
    });
	//上传图片
	 var tmpl = '<div class="upload-img" style="background-image:url(#url#)"><a class="close" id="close" href="javascript:;">×</a></div>';
	    $('.upload-input').change(function(e){
	        var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
	        for (var i = 0, len = files.length; i < len; ++i) {
	            var file = files[i];
	            if (file.size/1024 > 2048) {
	            	alert('图片不能大于2M');
	            	return;
				}
	            if (url) {
	                src = url.createObjectURL(file);
	            } else {
	                src = e.target.result;
	            }
	            $(this).parents(".upload").append($(tmpl.replace('#url#', src)));
	            $(this).parents(".upload-file").addClass('hide');
	        }
	    });
	
	    $('.upload').on('click','#close',function(){
            $(this).parent().siblings(".upload-file").find('input').val('');
	        $(this).parent().siblings(".upload-file").removeClass('hide');
	        $(this).parent().remove();
	    });

});
//检查用户是否登陆
function checkLogin()
{
	$.ajax({
		data:{cheklogin:1},
		dataType:'json',
		url:'index.php?act=index&op=_cheklogin',
		type:'post',
		success:function(data){
			if(data.code==400){
              window.location.href ='index.php?act=login&op=index';
			}
		}

	});
}

//检测地图
function checkMap(addres_name,host)
{
	var url = host+'/wxweb/index.php?act=map&op=index&addr='+addres_name;
	window.app && window.app.AppChooseMap(addres_name,url);
	window.webkit && window.webkit.messageHandlers.AppChooseMap.postMessage(addres_name,url);
}


